package org.rabbitmq.test3;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import org.rabbitmq.utils.RabbitMqUtils;

import java.util.Scanner;

public class Task2 {
    //队列名称
    public static final String TASK_QUEUE_NAME = "task";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        //声明队列
        //是否需要持久化
        boolean durable = true;
        channel.queueDeclare(TASK_QUEUE_NAME,durable,false,false,null);

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message= scanner.next();
            //设置生产者发送消息为持久化消息，报存在内存种

            channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
            System.out.println("消息发送成功"+message);
        }

    }
}
